<template>
	<div class="orderpage">
		<van-nav-bar title="确认订单">
			  <template #left>
			    <van-icon name="arrow-left" size="18" color="black" @click="backproduct"/>
			  </template>
			  <!-- <template #right>
			    <van-icon name="share-o" size="18" color="black"/>
			  </template> -->
		</van-nav-bar>
		<van-cell :title="shopname" icon="shop-o"  :to="{ name: 'shopindex' }"/>
        <van-card num="1" price="2.00" :desc="item.description" :title="item.title">
        	<template #thumb>
        		<van-image width="100" height="90" :src="item.cover" />
        	</template>
        	<template #price>
        		<span style="color:#aaa">￥{{item.price}}</span>
        	</template>
			 <template #footer>
			    <span>需付款：</span><span style="color:red;font-size:15px">{{item.price}}</span>
			  </template>
        </van-card>
		<div class="mt-10" style="height:5px;background:#eee" />
	    <xjcoupon :info_id="id" @click="$refs.coupon.showList=true;" ref="coupon"></xjcoupon>
		<div style="height:5px;background:#eee" />
		<!-- <van-cell title="留言" value="选填,建议和商家沟通后再填写" style="font-size: 12px;"/> -->
		<div style="position:absolute;bottom:0;height:30px;background:#eee;"></div>
		<div class="fixorder">
		 <span class="ml-10" style="font-size: 14px;">合计：</span>
		 <span style="color:red;font-size:12px">￥</span>
		 <span style="color:red;font-size: 19px;">{{pricearr[0]}}</span>
		 <span style="color:red;font-size: 14px;">{{pricearr[1]}}</span>
		 <van-button type="warning" class="fr" style="border-radius: 15px;height: 30px;margin-top:10px;margin-right: 10px;" @click="submitOrder">提交订单</van-button>
		</div>
	</div>
</template>

<script>
import xjcoupon from '@/components/frontshop/xjcoupon.vue';
	export default {
			components: {
         xjcoupon
        },
		data() {
			return {
				pricearr:[],
				id:'',
				item:'',
				randcode:'',
				shopname: localStorage.getItem('shopname')?localStorage.getItem('shopname'):'', //店铺名
				jian_price:0,
				ucp_id:0
			}
		},
		methods:{
			//添加支付订单
			async submitOrder(){
				let id=this.$route.query.id;
				//let ordernumber=order_number();
				let res=await this.$frontaxios.post(this.$front.addKnowledgeOrder,{id,ucp_id:this.ucp_id,randcode:this.randcode});
				if(res.code==1||res.code==0){
				 this.$router.push({name:'pay',query:{id,ordernumber:res.data.ordernumber,randcode:this.randcode}});//创建新订单成功
				 }else if(res.code==2){
					 this.$notify({type:'success',message:"你已经购买此商品，无需重复购买"})
				 }else{
					 this.$toast.fail('创建订单失败');
				 }
			},
			backproduct(){
				 this.$router.back();
				//this.$router.push({name:'product',query:{id:this.id}});
			},
			async getData(){
					this.id = this.$route.query.id;//单个知识id
			this.randcode=this.$route.query.randcode;
			let query = {
				id: this.id
			};
			let res = await this.$frontaxios.post(this.$front.getOneKnowledgeInfo, query);
			//console.log(res);
			if(res.code==1){
			this.item=res.data;
			this.item.price=(res.data.price*100-this.jian_price*100)/100;
			console.log(this.item.price);
			}
			else{
				console.log('得到单个知识获取失败');
			}
			if(this.item.price>0){
			let pricearr = this.item.price.toString().split('.');
			this.pricearr[0] = pricearr[0]+'.';
			this.pricearr[1] = pricearr[1]==undefined?'00':pricearr[1];
			}else if(this.item.price==0){
            this.pricearr[0] = 0+'.';
			this.pricearr[1] = '00';
			}
			}
		},
		async created(){
		     this.getData();
		}
		}
</script>

<style lang="scss" scoped>
	.orderpage{
	   height: 100vh;
	   background-color: #eee;
	   overflow: scroll;
	.fixorder{
	      position: fixed;
	      right: 0;
	      bottom: 0;
	      left: 0;
	      height: 50px;
	      background-color: #fafafa;
		  line-height: 50px;
	   }
	   .van-card{
	   	background-color: white;
	    }
	}
</style>
